package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.YYFBody;
import com.itheima.service.YYFBodyManagerService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/bodyManager")
public class YYFBodyManagerController {
    @Reference
    private YYFBodyManagerService yyfBodyManagerService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
       return yyfBodyManagerService.findPage(queryPageBean);
    }
    //根据ID查询数据,用于编辑弹窗的数据回显
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            YYFBody body = yyfBodyManagerService.findById(id);
            return new Result(true, MessageConstant.QUERY_BODY_SUCCESS,body);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_BODY_FAIL);
        }
    }
    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        try {
            yyfBodyManagerService.deleteById(id);
            return new Result(true,MessageConstant.DELETE_BODY_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.DELETE_BODY_FAIL);
        }
    }
    @RequestMapping("/edit")
    public Result edit(@RequestBody YYFBody body){
        try {
            yyfBodyManagerService.edit(body);
            return new Result(true,MessageConstant.EDIT_BODY_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.EDIT_BODY_FAIL);
        }
    }



}
